"""
应用配置文件
包含数据库连接、安全设置等配置
"""

import os

class DatabaseConfig:
    """数据库配置"""
    # MySQL配置
    MYSQL_HOST: str = os.getenv("MYSQL_HOST", "localhost")
    MYSQL_PORT: int = int(os.getenv("MYSQL_PORT", "3306"))
    MYSQL_USER: str = os.getenv("MYSQL_USER", "root")
    MYSQL_PASSWORD: str = os.getenv("MYSQL_PASSWORD", "ybj970911")
    # MYSQL_DATABASE: str = os.getenv("MYSQL_DATABASE", "weather_data")
    MYSQL_DATABASE: str = os.getenv("MYSQL_DATABASE", "library_manager")

    MYSQL_DATABASE_URL: str = f"mysql+pymysql://{MYSQL_USER}:{MYSQL_PASSWORD}@{MYSQL_HOST}:{MYSQL_PORT}/{MYSQL_DATABASE}"
    
    @classmethod
    def get_database_url(cls) -> str:
        """获取数据库URL"""
        return cls.MYSQL_DATABASE_URL

class AppConfig:
    """应用配置"""
    # 应用基本信息
    APP_NAME: str = "天气数据管理系统"
    APP_VERSION: str = "1.0.0"
    DEBUG: bool = os.getenv("DEBUG", "False").lower() == "true"
    
    # 服务器配置
    HOST: str = os.getenv("HOST", "0.0.0.0")
    PORT: int = int(os.getenv("PORT", "8000"))
    
    # 安全配置
    SECRET_KEY: str = os.getenv("SECRET_KEY", "your-secret-key-change-in-production")
    ACCESS_TOKEN_EXPIRE_MINUTES: int = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", "30"))
    
    # CORS配置
    ALLOWED_ORIGINS: list = [
        "http://localhost:5173",
        "http://127.0.0.1:5173",
        "http://localhost:3000",
        "http://127.0.0.1:3000"
    ]

class DefaultData:
    """默认数据配置"""
    # 默认用户配置
    DEFAULT_ADMIN_USERNAME: str = "admin"
    DEFAULT_ADMIN_PASSWORD: str = "admin123"
    DEFAULT_ADMIN_NAME: str = "管理员"
    
    DEFAULT_USER_USERNAME: str = "user"
    DEFAULT_USER_PASSWORD: str = "user123"
    DEFAULT_USER_NAME: str = "普通用户"
    
    # 测试数据配置
    SAMPLE_DATA_CITIES: list = ["北京", "上海", "深圳", "广州", "成都", "杭州"]
    SAMPLE_DATA_DAYS: int = 30  # 生成最近多少天的数据

# 创建全局配置实例
db_config = DatabaseConfig()
app_config = AppConfig()
default_data = DefaultData()

def print_config():
    """打印当前配置信息"""
    print("=" * 50)
    print("当前配置信息")
    print("=" * 50)
    print(f"数据库类型: MySQL")
    print(f"数据库URL: {db_config.get_database_url()}")
    print(f"应用名称: {app_config.APP_NAME}")
    print(f"应用版本: {app_config.APP_VERSION}")
    print(f"调试模式: {app_config.DEBUG}")
    print(f"服务器地址: {app_config.HOST}:{app_config.PORT}")
    print("=" * 50) 